﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Data;
using System.Collections;
using EntityDaoLibrary;

namespace BusinessRules
{
    public class YBYPInfoRules
    {
        public YBYPInfoRules()
		{
		}
				
		
		#region 业务规则层操作

		public void insertEntity(DataSet entityData)
		{
			IDataAccess data=DataAccessFactory.instance.CreateDataAccess();
			data.Open();
			SingleTransaction tran=new SingleTransaction(data);
			tran.Begin();
			try
			{
				YBYPInfoDAO dao=new YBYPInfoDAO(data);
				dao.insertEntity(entityData);
				tran.Commit();
			}
			catch(Exception e)
			{
				tran.Rollback();
				throw new Exception(e.Message ,e);
			}
			finally
			{
				data.Close();
			}
		}


		public void updateEntity(DataSet entityData)
		{
			IDataAccess data=DataAccessFactory.instance.CreateDataAccess();
			data.Open();
			SingleTransaction tran=new SingleTransaction(data);
			tran.Begin();
			try
			{
				YBYPInfoDAO dao=new YBYPInfoDAO(data);
				dao.updateEntity(entityData);
				tran.Commit();
			}
			catch(Exception e)
			{
				tran.Rollback();
				throw new Exception(e.Message ,e);
			}
			finally
			{
				data.Close();
			}
		}

		
		public void deleteEntity(DataSet entityData)
		{
			IDataAccess data=DataAccessFactory.instance.CreateDataAccess();
			data.Open();
			SingleTransaction tran=new SingleTransaction(data);
			tran.Begin();
			try
			{
				YBYPInfoDAO dao=new YBYPInfoDAO(data);
				dao.deleteEntity(entityData);
				tran.Commit();
			}
			catch(Exception e)
			{
				tran.Rollback();
				throw new Exception(e.Message ,e);
			}
			finally
			{
				data.Close();
			}
		}

		
		public DataSet FindByPrimaryKey(object strKeyValue)
		{
			IDataAccess data=DataAccessFactory.instance.CreateDataAccess();
			data.Open();
			try
			{
				YBYPInfoDAO dao=new YBYPInfoDAO(data);
				return dao.FindByPrimaryKey(strKeyValue);
			}
			catch(Exception e)
			{
				throw new Exception(e.Message ,e);
			}
			finally
			{
				data.Close();
			}
		}


		public DataSet FindByPrimaryKey(ArrayList KeyValue)
		{
			IDataAccess data=DataAccessFactory.instance.CreateDataAccess();
			data.Open();
			try
			{
				YBYPInfoDAO dao=new YBYPInfoDAO(data);
				return dao.FindByPrimaryKey(KeyValue);
			}
			catch(Exception e)
			{
				throw new Exception(e.Message ,e);
			}
			finally
			{
				data.Close();
			}
		}

		#endregion

        public void deleteEntity()
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                YBYPInfoDAO dao = new YBYPInfoDAO(data);
                dao.deleteEntity();
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }

        public DataSet FindAll()
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                YBYPInfoDAO dao = new YBYPInfoDAO(data);
                return dao.FindAll();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }
	}
    
}
